<?php

class DB
{
    public static $pdo;

    public function __construct()
    {
        $dsn = 'mysql:host=127.0.0.1;dbname=blog;charset=utf8';
        $user = 'root';
        $pwd = null;
        try {
            self::$pdo = new PDO($dsn, $user, $pwd);
            self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            return self::$pdo;
        } catch (PDOException $e) {
            throw new Exception('数据库错误：'. $e->getMessage());
        }
    }
}